package cn.org.xwb.common.model.vo;

import lombok.*;

import java.io.Serial;
import java.io.Serializable;

/**
 * 用于封装响应客户端数据的基本结果类
 *
 * @param <T> 响应客户端数据的类型
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class RespResult<T> implements Serializable {

    @Serial
    private static final long serialVersionUID = 1L;

    /**
     * 此次请求处理的状态，true-成功；false-失败
     */
    private Boolean status;

    /**
     * 响应信息
     */
    private String msg;

    /**
     * 响应结果数据
     */
    private T data;

    /**
     * 请求处理状态
     */
    @Getter
    public static enum Status {

        SUCCESS(true, "成功"),
        FAIL(false, "失败");

        /**
         * 此次请求处理的状态，true-成功；false-失败
         */
        private final Boolean status;

        /**
         * 此次请求处理状态对应的描述信息
         */
        private final String msg;

        private Status(Boolean status, String msg) {
            this.status = status;
            this.msg = msg;
        }
    }

    public static <T> RespResult<T> success() {
        return new RespResult<>(Status.SUCCESS.getStatus(), Status.SUCCESS.getMsg(), null);
    }

    public static <T> RespResult<T> success(String message) {
        return new RespResult<>(Status.SUCCESS.getStatus(), message, null);
    }

    public static <T> RespResult<T> success(T data) {
        return new RespResult<>(Status.SUCCESS.getStatus(), Status.SUCCESS.getMsg(), data);
    }

    public static <T> RespResult<T> success(String message, T data) {
        return new RespResult<>(Status.SUCCESS.getStatus(), message, data);
    }

    public static <T> RespResult<T> fail() {
        return new RespResult<>(Status.FAIL.getStatus(), Status.FAIL.getMsg(), null);
    }

    public static <T> RespResult<T> fail(String message) {
        return new RespResult<>(Status.FAIL.getStatus(), message, null);
    }

    public static <T> RespResult<T> fail(T data) {
        return new RespResult<>(Status.FAIL.getStatus(), Status.FAIL.getMsg(), data);
    }

    public static <T> RespResult<T> fail(String message, T data) {
        return new RespResult<>(Status.FAIL.getStatus(), message, data);
    }

}
